<!DOCTYPE HTML>
<html>
<head>
    <title>群主加分管理</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body style="padding: 0;width: 100%;height: 98%">
<div style="width:100%;height:88%;">

    <div id="outImg">
        <img id="imgId" src="" alt="" onclick="smallImg()">
    </div>
    <div style="padding: 5px">
        <span>部落名称：</span><input class="mini-textbox" type="text" id="name"/>
        <span>部落ID：</span><input class="mini-textbox" type="text" id="objectId"/>
        <span>部落主ID：</span><input class="mini-textbox" type="text" id="creater"/>
        <span>部落主昵称：</span><input class="mini-textbox" type="text" id="nickName"/>
        <!--<span>部落号：</span><input class="mini-textbox" type="text" id="numNumber"/>-->
        <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
    </div>
    <div style="width:99%;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
                        <a class="mini-button" iconCls="icon-add" onclick="add()">添加</a>
                        <a class="mini-button" iconCls="icon-remove" onclick="del()">删除</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 100%;"
         url="/tribeRoute/tribeBonus" idField="id" allowResize="true"
         sizeList="[20,30,50,100]" pageSize="20"
    >
        <div property="columns">
            <div type="checkcolumn" width="20"></div>
            <div field="creater" width="30" align="center" headerAlign="center">部落主ID</div>
            <div field="nickName" width="30" align="center" headerAlign="center">部落主昵称</div>
            <div field="gender" width="30" align="center" headerAlign="center" renderer="onGenderRenderer"
                 allowSort="true">部落主iocn
            </div>
            <div field="objectId" width="30" align="center" headerAlign="center">部落ID</div>
            <div field="name" width="30" align="center" headerAlign="center">部落名称</div>
            <div field="possibleChange" width="30" align="center" headerAlign="center" >是否可加分</div>
            <div field="maxNum" width="30" align="center" headerAlign="center">加分最多</div>
            <div field="createdAt" width="40" align="center" headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss">
                创建日期
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var flag = 1;
    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load();
    grid.on("drawcell", function (e) {
        var value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "gender") {
            if (value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            } else {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
        if(column.field == "possibleChange") {
            if(value ==0){
                e.cellHtml = '<text>不可加分</text>';
            }else{
                e.cellHtml = '<text>可加分</text>';
            }
        }
    });

    var Genders = [{id: 1, text: '男'}, {id: 2, text: '女'}];
    function onGenderRenderer(e) {
        for (var i = 0, l = Genders.length; i < l; i++) {
            var g = Genders[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }


    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            if (flag == 1) {
                var path = row.gender;
                $("#imgId").attr('src', path);
                $("#outImg").css('display', 'block');
            }
        }
    }
    function smallImg() {
        $("#outImg").css('display', 'none');
    }
    function edit() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/tribeRoute/tribeBonusEdit?objectId="+row.objectId,
                title: "编辑加分管理", width: 600, height: 220,
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请选中一个部落!");
            return;
        }
    }
    function add() {
      mini.open({
        url: "/tribeRoute/tribeBonusAdd",
        title: "选择部落", width: 600, height: 400,
        ondestroy: function (action) {
          tribeOId = '';
          grid.reload();
        }
      });
    }
    function del() {
      var row = grid.getSelected();
      if (row) {
        var objectId = row.objectId;
        $.ajax({
          url: "/tribeRoute/tribeBonusRemove",
          type: 'post',
          data: {objectId: objectId},
          cache: false,
          success: function (result) {
//            console.log(result);
            var funResult = JSON.parse(result);
            if (funResult.possibleChange === '0' && funResult.objectId === objectId) {
              alert('部落加分状态修改成功！');
            } else {
              alert('部落加分状态修改失败，请重试！');
              return;
            }
            tribeOId = '';
            grid.reload();
          },
          error: function (error) {
            console.log(error)
          }
        });
      } else {
        alert("请选中一条记录");
      }
    };
    function search() {
      var name = mini.get("name").getValue();
      var objectId = mini.get("objectId").getValue();
      var creater = mini.get("creater").getValue();
      var nickName = mini.get("nickName").getValue();
//      var numNumber = mini.get("numNumber").getValue();
//      if (name == "" && objectId == "" && creater == "" && nickName == "" && numNumber == "") {
//        alert('请输入查询条件！')
//      } else {
//        grid.load({
//          name: name,
//          objectId: objectId,
//          creater: creater,
//          nickName: nickName,
//          numNumber: numNumber,
//        });
//      }
      grid.load({
        name: name,
        objectId: objectId,
        creater: creater,
        nickName: nickName,
//        numNumber: numNumber,
      });
    }
</script>
</html>